package com.hanrui.android.fragment.message.audit.chapter;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.activity.download.MyDownLoadActivity;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.ChapterDetailBean;
import com.hanrui.android.model.FilesBean;
import com.hanrui.android.net.contract.message.audit.chapter.ChapterDetailContract;
import com.hanrui.android.net.presenter.message.audit.chapter.ChapterDetailPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 用章审批基本信息
 *
 */

public class ChapterDetailFragment extends BaseFragment<ChapterDetailPresenter> implements ChapterDetailContract.View {
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.thing_title)
    TextView thingTitle;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.leaders)
    TextView leaders;
    @BindView(R.id.head_company)
    ImageView headCompany;
    @BindView(R.id.duty_company)
    ImageView dutyCompany;
    @BindView(R.id.assign_body)
    TextView assignBody;
    @BindView(R.id.duty_people)
    TextView dutyPeople;
    @BindView(R.id.from)
    TextView from;
    @BindView(R.id.base_data)
    TextView baseData;
    @BindView(R.id.vote_meet)
    TextView voteMeet;
    @BindView(R.id.money_meet)
    TextView moneyMeet;
    @BindView(R.id.wind_meet)
    TextView windMeet;
    @BindView(R.id.party_meet)
    TextView partyMeet;
    @BindView(R.id.group_meet)
    TextView groupMeet;
    @BindView(R.id.work_content)
    TextView workContent;
    @BindView(R.id.keyword)
    TextView keyword;
    @BindView(R.id.reson)
    TextView reson;
    @BindView(R.id.head_ll)
    LinearLayout headLl;
    @BindView(R.id.enclosure_num)
    TextView enclosureNum;
    @BindView(R.id.duty_ll)
    LinearLayout dutyLl;
    @BindView(R.id.enclosure_num1)
    TextView enclosureNum1;

    List<FilesBean> sealUse = new ArrayList<>();
    List<FilesBean> sealUsereference = new ArrayList<>();

    String taskId,procInsId,bizId;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_chapterdetail;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.chapterABizDetail(getActivity(),taskId,procInsId,bizId);

    }



    public static ChapterDetailFragment newInstance(String taskId,String procInsId,String bizId) {
        ChapterDetailFragment fragment = new ChapterDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putString("taskId", taskId);
        bundle.putString("procInsId", procInsId);
        bundle.putString("bizId", bizId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @OnClick({R.id.head_company,R.id.duty_company})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.head_company:
                MyDownLoadActivity.start(getActivity(),sealUse);
                break;
            case R.id.duty_company:
                MyDownLoadActivity.start(getActivity(),sealUsereference);
                break;
        		}
    }

    @Override
    public void chapterABizDetail(ChapterDetailBean data) {

        if (null != data) {

            mainTitle.setText(data.getDetail().getApplyPerson()+"的用章审批");
            subheadTitle.setText(data.getDetail().getCreateDate());
            name.setText(data.getDetail().getApplyPerson());
            thingTitle.setText(data.getDetail().getApplyCompany());
            time.setText(data.getDetail().getShowOfficeName());
            leaders.setText(data.getDetail().getSealTypeName());
            assignBody.setText(data.getDetail().getPerson());
            dutyPeople.setText(data.getDetail().getType());
            from.setText(data.getDetail().getMeetingType());
            baseData.setText(data.getDetail().getBasicInfor());
            voteMeet.setText(data.getDetail().getVoteName());
            moneyMeet.setText(data.getDetail().getCapitalName());
            windMeet.setText(data.getDetail().getRiskExamineName());
            partyMeet.setText(data.getDetail().getCommittee());
            groupMeet.setText(data.getDetail().getMeetingApplyName());
            workContent.setText(data.getDetail().getContent());
            keyword.setText(data.getDetail().getKeyword());
            reson.setText(data.getDetail().getRemarks());


            sealUse.clear();
            sealUsereference.clear();
            if (null != data.getFiles() && data.getFiles().size() > 0) {
                for (int i = 0; i < data.getFiles().size(); i++) {

                    String type = data.getFiles().get(i).getFileType();
                    if (type.equals("sealUse")) {

                        sealUse.add(data.getFiles().get(i));

                    		}else {

                        sealUsereference.add(data.getFiles().get(i));
                    }

                }
            		}


            if (sealUse.size() > 0) {

                headLl.setVisibility(View.VISIBLE);
                enclosureNum.setText("["+sealUse.size()+"]");

            		}

            if (sealUsereference.size() > 0) {

                dutyLl.setVisibility(View.VISIBLE);
                enclosureNum1.setText("["+sealUsereference.size()+"]");

            		}

        		}

    }
}
